package(default_visibility = ["//tools/build_defs:internal_pkg"])

licenses(["notice"])  # Apache 2.0

PUBLIC_APIS = [
    "common_enums.h",
    "aes_gcm_boringssl.h",
    "encrypt_then_authenticate.h",
    "hmac_boringssl.h",
    "hkdf.h",
    "ind_cpa_cipher.h",
    "random.h",
]

cc_library(
    name = "subtle",
    hdrs = PUBLIC_APIS,
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    visibility = ["//visibility:public"],
    deps = [
        ":aes_gcm_boringssl",
        ":common_enums",
        ":encrypt_then_authenticate",
        ":hkdf",
        ":hmac_boringssl",
        ":random",
        "//cc:aead",
        "//cc:hybrid_decrypt",
        "//cc:hybrid_encrypt",
        "//cc:mac",
        "//cc:public_key_sign",
        "//cc:public_key_verify",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "ind_cpa_cipher",
    hdrs = ["ind_cpa_cipher.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        "//cc/util:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "ecies_hkdf_recipient_kem_boringssl",
    srcs = ["ecies_hkdf_recipient_kem_boringssl.cc"],
    hdrs = ["ecies_hkdf_recipient_kem_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":hkdf",
        ":subtle_util_boringssl",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "ecies_hkdf_sender_kem_boringssl",
    srcs = ["ecies_hkdf_sender_kem_boringssl.cc"],
    hdrs = ["ecies_hkdf_sender_kem_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":hkdf",
        ":subtle_util_boringssl",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "ec_util",
    srcs = ["ec_util.cc"],
    hdrs = ["ec_util.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "hkdf",
    srcs = ["hkdf.cc"],
    hdrs = ["hkdf.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "hmac_boringssl",
    srcs = ["hmac_boringssl.cc"],
    hdrs = ["hmac_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc:mac",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "ecdsa_sign_boringssl",
    srcs = ["ecdsa_sign_boringssl.cc"],
    hdrs = ["ecdsa_sign_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc:public_key_sign",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "ecdsa_verify_boringssl",
    srcs = ["ecdsa_verify_boringssl.cc"],
    hdrs = ["ecdsa_verify_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc:public_key_verify",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "rsa_ssa_pss_verify_boringssl",
    srcs = ["rsa_ssa_pss_verify_boringssl.cc"],
    hdrs = ["rsa_ssa_pss_verify_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc:public_key_verify",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "rsa_ssa_pss_sign_boringssl",
    srcs = ["rsa_ssa_pss_sign_boringssl.cc"],
    hdrs = ["rsa_ssa_pss_sign_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc:public_key_sign",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "rsa_ssa_pkcs1_verify_boringssl",
    srcs = ["rsa_ssa_pkcs1_verify_boringssl.cc"],
    hdrs = ["rsa_ssa_pkcs1_verify_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc:public_key_verify",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "rsa_ssa_pkcs1_sign_boringssl",
    srcs = ["rsa_ssa_pkcs1_sign_boringssl.cc"],
    hdrs = ["rsa_ssa_pkcs1_sign_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":subtle_util_boringssl",
        "//cc:public_key_sign",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "aes_gcm_boringssl",
    srcs = ["aes_gcm_boringssl.cc"],
    hdrs = ["aes_gcm_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":random",
        ":subtle_util_boringssl",
        "//cc:aead",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "aes_eax_boringssl",
    srcs = ["aes_eax_boringssl.cc"],
    hdrs = ["aes_eax_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":random",
        ":subtle_util_boringssl",
        "//cc:aead",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "encrypt_then_authenticate",
    srcs = ["encrypt_then_authenticate.cc"],
    hdrs = ["encrypt_then_authenticate.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":aes_ctr_boringssl",
        ":ind_cpa_cipher",
        ":subtle_util_boringssl",
        "//cc:aead",
        "//cc:mac",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "aes_ctr_boringssl",
    srcs = ["aes_ctr_boringssl.cc"],
    hdrs = ["aes_ctr_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":ind_cpa_cipher",
        ":random",
        ":subtle_util_boringssl",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "random",
    srcs = ["random.cc"],
    hdrs = ["random.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        "@boringssl//:crypto",
    ],
)

cc_library(
    name = "xchacha20_poly1305_boringssl",
    srcs = ["xchacha20_poly1305_boringssl.cc"],
    hdrs = ["xchacha20_poly1305_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        ":random",
        ":subtle_util_boringssl",
        "//cc:aead",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "common_enums",
    srcs = ["common_enums.cc"],
    hdrs = ["common_enums.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
)

cc_library(
    name = "subtle_util_boringssl",
    srcs = ["subtle_util_boringssl.cc"],
    hdrs = ["subtle_util_boringssl.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        "//cc/util:errors",
        "//cc/util:status",
        "//cc/util:statusor",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "wycheproof_util",
    srcs = ["wycheproof_util.cc"],
    hdrs = ["wycheproof_util.h"],
    include_prefix = "tink",
    strip_include_prefix = "/cc",
    deps = [
        ":common_enums",
        "//cc/util:status",
        "//cc/util:statusor",
        "@com_google_absl//absl/strings",
        "@rapidjson",
    ],
)

# tests

cc_test(
    name = "ecies_hkdf_recipient_kem_boringssl_test",
    size = "small",
    srcs = ["ecies_hkdf_recipient_kem_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":common_enums",
        ":ecies_hkdf_recipient_kem_boringssl",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "ecies_hkdf_sender_kem_boringssl_test",
    size = "small",
    srcs = ["ecies_hkdf_sender_kem_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":common_enums",
        ":ecies_hkdf_recipient_kem_boringssl",
        ":ecies_hkdf_sender_kem_boringssl",
        ":subtle_util_boringssl",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "ec_util_test",
    size = "small",
    srcs = ["ec_util_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":ec_util",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "hkdf_test",
    size = "small",
    srcs = ["hkdf_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":common_enums",
        ":hkdf",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "hmac_boringssl_test",
    size = "small",
    srcs = ["hmac_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":common_enums",
        ":hmac_boringssl",
        "//cc:mac",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "aes_gcm_boringssl_test",
    size = "small",
    srcs = ["aes_gcm_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    data = [
        "@wycheproof//testvectors:aes_gcm",
    ],
    deps = [
        ":aes_gcm_boringssl",
        ":wycheproof_util",
        "//cc:aead",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@rapidjson",
    ],
)

cc_test(
    name = "aes_eax_boringssl_test",
    size = "small",
    srcs = ["aes_eax_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    data = [
        "@wycheproof//testvectors:aes_eax",
    ],
    deps = [
        ":aes_eax_boringssl",
        ":common_enums",
        ":wycheproof_util",
        "//cc:aead",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@rapidjson",
    ],
)

cc_test(
    name = "encrypt_then_authenticate_test",
    size = "small",
    srcs = ["encrypt_then_authenticate_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":aes_ctr_boringssl",
        ":common_enums",
        ":encrypt_then_authenticate",
        ":hmac_boringssl",
        ":random",
        "//cc:aead",
        "//cc:mac",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "aes_ctr_boringssl_test",
    size = "small",
    srcs = ["aes_ctr_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":aes_ctr_boringssl",
        ":random",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "ecdsa_sign_boringssl_test",
    size = "small",
    srcs = ["ecdsa_sign_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":common_enums",
        ":ec_util",
        ":ecdsa_sign_boringssl",
        ":ecdsa_verify_boringssl",
        "//cc:public_key_sign",
        "//cc:public_key_verify",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "ecdsa_verify_boringssl_test",
    size = "small",
    srcs = ["ecdsa_verify_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    data = [
        "@wycheproof//testvectors:all",
    ],
    deps = [
        ":common_enums",
        ":ecdsa_sign_boringssl",
        ":ecdsa_verify_boringssl",
        ":wycheproof_util",
        "//cc:public_key_sign",
        "//cc:public_key_verify",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@rapidjson",
    ],
)

cc_test(
    name = "rsa_ssa_pss_verify_boringssl_test",
    size = "small",
    srcs = ["rsa_ssa_pss_verify_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    data = [
        "@wycheproof//testvectors:all",
    ],
    deps = [
        ":common_enums",
        ":rsa_ssa_pss_verify_boringssl",
        ":wycheproof_util",
        "//cc:public_key_sign",
        "//cc:public_key_verify",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@rapidjson",
    ],
)

cc_test(
    name = "rsa_ssa_pss_sign_boringssl_test",
    size = "small",
    srcs = ["rsa_ssa_pss_sign_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":rsa_ssa_pss_sign_boringssl",
        ":rsa_ssa_pss_verify_boringssl",
        ":subtle_util_boringssl",
        "//cc/util:test_matchers",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "rsa_ssa_pkcs1_verify_boringssl_test",
    size = "small",
    srcs = ["rsa_ssa_pkcs1_verify_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    data = [
        "@wycheproof//testvectors:all",
    ],
    deps = [
        ":common_enums",
        ":rsa_ssa_pkcs1_verify_boringssl",
        ":wycheproof_util",
        "//cc:public_key_sign",
        "//cc:public_key_verify",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@rapidjson",
    ],
)

cc_test(
    name = "rsa_ssa_pkcs1_sign_boringssl_test",
    size = "small",
    srcs = ["rsa_ssa_pkcs1_sign_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":rsa_ssa_pkcs1_sign_boringssl",
        ":rsa_ssa_pkcs1_verify_boringssl",
        ":subtle_util_boringssl",
        "//cc/util:test_matchers",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "random_test",
    size = "small",
    srcs = ["random_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    linkopts = ["-pthread"],
    deps = [
        ":random",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "common_enums_test",
    size = "small",
    srcs = ["common_enums_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    linkopts = ["-pthread"],
    deps = [
        ":common_enums",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "subtle_util_boringssl_test",
    size = "small",
    srcs = ["subtle_util_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    data = [
        "@wycheproof//testvectors:ecdh",
    ],
    linkopts = ["-pthread"],
    deps = [
        ":ec_util",
        ":subtle_util_boringssl",
        ":wycheproof_util",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_matchers",
        "//cc/util:test_util",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@rapidjson",
    ],
)

cc_test(
    name = "xchacha20_poly1305_boringssl_test",
    size = "small",
    srcs = ["xchacha20_poly1305_boringssl_test.cc"],
    copts = ["-Iexternal/gtest/include"],
    deps = [
        ":xchacha20_poly1305_boringssl",
        "//cc:aead",
        "//cc/util:status",
        "//cc/util:statusor",
        "//cc/util:test_util",
        "@boringssl//:crypto",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)
